/**
* 作者 ：食草狂魔
*
* 日期 ：2017/11/28
*
* 描述 ：目录管理组件 - 添加目录分类
*/
<template>
  <div class="dialogContent">
    <el-form class="addDepartmentForm" label-position="right" label-width="110px" :model="ruleForm" ref="addCatalogTypeForm">
      <el-row class="dialogBar">
        <el-col class="title">数据资源分类管理</el-col>
      </el-row>
      <el-form-item label="所属分类 :" style="margin-top: 20px;">
        <p>{{addCatalogTypeFormData.data.label}}</p>
      </el-form-item>
      <el-form-item label="目录名称 :" prop="name" style="margin-top: 20px;">
        <el-input v-model="ruleForm.name" class="shortText"></el-input>
      </el-form-item>
      <el-form-item label="目录编码 :" prop="code" style="margin-top: 20px;">
        <el-input v-model="ruleForm.code" class="shortText"></el-input>
      </el-form-item>
      <el-form-item label="目录描述 :" prop="description">
        <el-input type="textarea" v-model="ruleForm.abstracts" class="longText" rows="5"></el-input>
      </el-form-item>
      <el-form-item label-width="0px" style="margin-top: 20px;text-align: center;">
        <el-button class="moduleButton button" :plain="true" type="primary" @click="submitForm()">保存</el-button>
        <el-button class="button" type="info" @click="resetForm()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import dirAPIs from '../../../../api/dirAPIs'
  export default {
    props: ["parentModel", "addCatalogTypeFormData"],
    name: "addCatalogTypeForm",
    data () {
      return {
        ruleForm: {
          name: "",
          code: "",
          abstracts: "",
          dirTypeId: this.$props.addCatalogTypeFormData.data.rootId?this.$props.addCatalogTypeFormData.data.rootId:this.$props.addCatalogTypeFormData.data.value,
          parentId: this.$props.addCatalogTypeFormData.data.rootId?this.$props.addCatalogTypeFormData.data.value:"",
          token: localStorage.token
        }
      }
    },
    mounted: function () {
      let vm = this
    },
    methods: {
      submitForm () {
        let vm = this
        dirAPIs.infoDirInsert(vm.ruleForm).then(({ data }) => {
          if(data.code == 10000) {
            vm.$message.success('添加信息资源分类成功！')
//            debugger
//            vm.$props.parentModel.loadTreeData()
            vm.$parent.visible = false

            const newChild = { value: data.data, code:vm.ruleForm.code, label: vm.ruleForm.name, rootId:vm.ruleForm.dirTypeId, children: [] };
            if (!vm.$props.addCatalogTypeFormData.data.children) {
              vm.$set(vm.$props.addCatalogTypeFormData.data, 'children', []);
            }
            vm.$props.addCatalogTypeFormData.data.children.push(newChild);
          }
          else {
            vm.$message.error('添加信息资源分类失败！')
          }
        })
      },
      resetForm () {
        let vm = this
        vm.$parent.visible = false
      }
    }
  }
</script>
<style>
  .dialogContent .dialogBar{
    height: 35px;
    line-height: 35px;
    background-color: #ebebeb;
    border-left: 4px solid #2cace2;
    text-align: left;
    width: 97%;
    margin: 0 auto;
  }
  .dialogContent .dialogBar .title{
    margin-left: 10px;
    color: #2cace2;
    font-size: 1.8rem;
  }
  .dialogContent .shortText{
    width: 45%;
  }
  .dialogContent .longText {
    width: 96%;
  }
  .addDepartmentForm .button{
    width: 112px;
    height: 36px;
    padding: 0;
  }
  .addDepartmentForm button:first-child{
    margin-right: 60px;
  }
</style>
